Skip to content

Igor/character creation#65

Merged
igor47 merged 2 commits intomainfrom
igor/character-creation
Feb 6, 2026
Merged

Igor/character creation#65
igor47 merged 2 commits intomainfrom
igor/character-creation

Conversation

@igor47
Copy link
Owner

@igor47 igor47 commented Feb 6, 2026

Refactor character creation for better error messages and to prevent missing fields.

we make the zod schema representative, and handle checks logic in the component
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors character creation validation to rely more on Zod-driven parsing/errors, improving required-field handling and surfaced error messages during both submit and live (is_check) validation.

Changes:

  • Move createCharacter to Zod-parse first and convert Zod errors via zodToFormErrors.
  • Tighten schema constraints for required fields and SRD 5.2 background ability bonuses (cap per-ability bonus at +2).
  • Add UI-side filtering to suppress empty-field errors during live (is_check) validation and add/adjust related tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/services/createCharacter.ts Refactors validation flow to parse with Zod first; updates schema requirements and SRD 5.2 bonus validation.
src/services/createCharacter.test.ts Adds coverage for missing class messaging; updates SRD 5.2 bonus validation expectation.
src/lib/formErrors.ts Enhances Zod issue flattening (nested union paths) and adds ignoreCheckEmptyErrors.
src/components/CharacterNew.tsx Filters out empty-field errors during live validation using ignoreCheckEmptyErrors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -27,11 +27,11 @@ import { addLevel } from "./addLevel"
*/
const BaseCharacterSchema = z.object({
name: z.string().min(3, "Pick a better character name!").max(50, "That name is too long!"),
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name validation no longer trims whitespace. As written, a value like " " (3+ spaces) passes z.string().min(3, ...) and will proceed to uniqueness + DB insert, whereas the previous logic rejected whitespace-only names via trim(). Consider applying .trim() in the Zod schema (or a refine) and using a required/empty message for the blank-after-trim case.

Suggested change
name: z.string().min(3, "Pick a better character name!").max(50, "That name is too long!"),
name: z
.string()
.trim()
.min(1, "Character name is required")
.min(3, "Pick a better character name!")
.max(50, "That name is too long!"),

Copilot uses AI. Check for mistakes.
@igor47 igor47 force-pushed the igor/character-creation branch from 3d759cc to 818d8d4 Compare February 6, 2026 22:40
@igor47 igor47 merged commit fc4a66a into main Feb 6, 2026
2 checks passed
@igor47 igor47 deleted the igor/character-creation branch February 6, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants